import QtQuick 2.0
import QtMultimedia 5.12
import QtAV 1.6

Item {
    property alias source: player.source
    property alias volume: player.volume
    property alias status: player.status
    property bool isRunning: true

    function play() {
        player.play();
    }

    function pause() {
        pause: player.pause();
    }

    signal ready()
    signal loading()
    signal loadError()

    Video {
        id: player
        anchors.fill: parent
        autoPlay: true

        onPlaying: {
            isRunning = true;
            playIcone.visible = false;
        }

        onPaused: {
            isRunning = false;
            playIcone.visible = true;
        }

        onStopped: {
            isRunning = false;
            playIcone.visible = true;
        }

        onSourceChanged: {
            emit: loading();
        }

        onStatusChanged: {
            if (status === MediaPlayer.Buffered) {
                emit: ready();
            } else if (status === 8) {
                emit: loadError();
            } else {
                emit: loading();
            }
        }

        Image {
            id: playIcone
            visible: false
            source: "qrc:/image/play.svg"
            anchors.right: parent.right
            anchors.rightMargin: height * 0.3
            anchors.bottom: parent.bottom
            anchors.bottomMargin: anchors.rightMargin
            height: parent.height * 0.2
            width: height
        }
    }
}
